package work.huangxin.share.controller.delivery;

import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import work.huangxin.share.domain.delivery.DeliveryInfo;
import work.huangxin.share.service.DeliveryInfoService;
import work.huangxin.share.util.status.BaseResponse;
import work.huangxin.share.util.status.ResponseData;

import java.util.ArrayList;
import java.util.List;

/**
 * (deliveryInfo) 控制层
 *
 * @author 张锦标
 * @since 2023-04-24 21:29:50
 */
@RestController
@RequestMapping("/wx/delivery")
public class DeliveryInfoController {

    @Autowired
    private DeliveryInfoService deliveryInfoService;

    @PostMapping("/create")
    public BaseResponse create(@RequestBody DeliveryInfo deliveryInfo){
        long id = deliveryInfoService.insertDeliveryInfo(deliveryInfo);
        return ResponseData.success(id);
    }
    @DeleteMapping("/delete")
    public BaseResponse delete(@RequestParam("ids")List<Long> ids){
        deliveryInfoService.deleteDeliveryInfo(ids);
        return ResponseData.success("批量删除成功");
    }
    @PutMapping("/edit")
    public BaseResponse update(@RequestBody DeliveryInfo deliveryInfo){
        boolean b = deliveryInfoService.updateDeliveryInfo(deliveryInfo);
        if (b){
            return ResponseData.success("修改成功");
        }else{
            return ResponseData.error(500,"修改失败");
        }
    }
    @GetMapping("/get/{id}")
    public BaseResponse getDeliveryInfoById(@PathVariable("id")Long id){
        DeliveryInfo deliveryInfo = deliveryInfoService.selectDeliveryInfoById(id);
        return ResponseData.success(deliveryInfo);
    }
    @GetMapping("/page")
    public BaseResponse page(@RequestParam("pageNum")Integer pageNum,
                             @RequestParam("pageSize")Integer pageSize){
        PageInfo<DeliveryInfo> deliveryInfoList = deliveryInfoService.selectDeliveryInfoPage(pageNum,pageSize);
        return ResponseData.success(deliveryInfoList);
    }
}

